<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
   <div>
      用户名： <input type="text"> <br><br>
      密码： <input type="password"> <br> <br> 
      <button>登录</button>  
   </div> 
</body>  
<script>
    var  input=document.getElementsByTagName("input")
    console.log(input[0])
    console.log(input[1])
    for(var i=0;i<input.length;i++){
         input[i].onfocus=function(){
              this.className="focus"
         }
         input[i].onblur=function(){
              this.className=""
         }

    }
</script>
</html>
<style>
div{
    width: 300px;
    height: 170px;
    border: 1px solid hotpink;
    text-align: center;   
    padding-top: 10px;
    margin:  0 auto;
}
button{
    background-color: hotpink;
    border: 0;
    color: white;
}
div .focus{
     background-color: hotpink;
}
</style>